<template>
  <el-form :model="detailForm" ref="detailForm" :inline="false"
           :label-position="labelPosition">

    <!-- 其他保险 -->
    <el-card class="box-card" shadow="never">

      <div slot="header" class="header-card">
        <span class="header-card-title">退保信息</span>
      </div>

      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="退保保费:" v-if="isShow" prop="refundInsuranceAmount">
            <el-input v-model="detailForm.refundInsuranceAmount" v-if="isEdit"  v-thousand
                      @change="changeAmount('refundInsuranceAmount')" placeholder="请输入其他保险保费合计"></el-input>
            <span v-else>{{ format_thousand(detailForm.refundInsuranceAmount) }}</span>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="退保生效日期:" v-if="isShow" prop="refundInsuranceTime">
            <el-date-picker v-model="detailForm.refundInsuranceTime" type="date" placeholder="请选择退保生效日期"
                            v-if="isEdit"
                            value-format='yyyy-MM-dd' style="width: 100%;">
            </el-date-picker>
            <span v-else>{{ detailForm.refundInsuranceTime }}</span>
          </el-form-item>
        </el-col>


      </el-row>
    </el-card>

  </el-form>
</template>

<script>
export default {
  name: "refundInfo", //退保信息

  props: {
    value: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: "",
    },
  },

  computed: {
    detailForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    labelPosition() {

      return 'right'
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool
    },
  },

  watch: {},

  data() {
    return {
      isShow: true,
    };
  },

  methods: {
    changeAmount(str) {
      let msg = /^(?:[1-9]\d*|0)(?:\.\d+)?$/;
      if (!msg.test(this.detailForm[str])) {
        this.detailForm[str] = "";
      } else {
        this.detailForm[str] = this.detailForm[str]
            .toString()
            .match(/^\d+(?:\.\d{0,2})?/)[0];
      }
    },
  },
};
</script>


<style lang="scss" scoped>
.box-card {
  font-size: 14px;
  margin-bottom: 16px;
}
.el-form-item{
  width: 70%;
}
</style>
